package com.xingkeduo.business.order.controller;

import com.alibaba.fastjson.JSON;
import com.xingkeduo.business.order.service.CommentsService;
import com.xingkeduo.business.order.service.OperateService;
import com.xingkeduo.business.order.service.WordPadService;
import com.xingkeduo.dto.PayResult;
import com.xingkeduo.dto.param.ConsumerPrivateParameterDto;
import com.xingkeduo.dto.param.OrderAddParameterDto;
import com.xingkeduo.dto.param.PayDetailParameterDto;
import com.xingkeduo.dto.param.ShopsParameterDto;
import com.xingkeduo.dto.transter.CancelPay;
import com.xingkeduo.dto.transter.appointment.AppointmentParamDto;
import com.xingkeduo.dto.transter.appointment.AppointmentSubmit;
import com.xingkeduo.dto.transter.appointment.CheckNewUserCouponDto;
import com.xingkeduo.dto.transter.orderadd.OrderAdd;
import com.xingkeduo.dto.transter.paydetail.PayDetail;
import com.xingkeduo.dto.transter.upload.CertifyResult;
import com.xingkeduo.dto.transter.upload.ImgResult;
import com.xingkeduo.json.BaseDTOJTO;
import com.xingkeduo.remote.OrderRemoteService;
import com.xingkeduo.remote.feign.MarketingFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author chi  2019-05-04 11:57
 **/



@RestController
@RequestMapping("/mobile2")
@Slf4j
public class Mobile2Controller {

    @Resource
    private WordPadService wordPadService;

    @Resource
    private CommentsService commentsService;

    @Resource
    private OrderRemoteService orderRemoteService;
    @Resource
    private OperateService operateService;

    @Resource
    private MarketingFeignService marketingFeignService;
    
    /**
     * 获取店铺详情
     * @param shopsParameterDto
     * @return
     */
    @GetMapping("/store_detail")
    public String store_detail(ShopsParameterDto shopsParameterDto){
        return operateService.store_detail(shopsParameterDto);
    }
    
    /**
     * @desc：写死数据 二维码路径      pantong  2019年5月9日下午9:54:18
     * @param consumerPrivateParameterDto
     * @return
     * Object
     */
    @RequestMapping("/steward_qrcode")
    public Object steward_qrcode(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
    	return BaseDTOJTO.toJsonForSteward_qrcode();
    }
    /**
     * @desc： 检测店铺详情页modal
     * @author: pantong  
     * @date: 2019年5月8日 上午11:29:05
     */
    @RequestMapping("/store_detail_modal")
    public Object store_detail_modal(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
    	return BaseDTOJTO.toJsonForCheck_store_detail_modal();
    }
    
    /**
     * 判断订单详情modal  pantong  2019年5月16日下午1:48:01
     * @param consumerPrivateParameterDto
     * @return
     * Object
     */
    @RequestMapping("/order_detail_modal")
    public Object order_detail_modal(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        //TODO 后期打开 2019/08/01
//        Boolean bf = commentsService.orderDetailModal(consumerPrivateParameterDto);
//        if(bf){
//            return BaseDTOJTO.toJsonForCheckModal();
//        }
        return BaseDTOJTO.toJsonForCheck_order_detail_modal();
    }
    
    //检查是否有新用户券
    @RequestMapping("/check_new_user_coupon")
    public Object check_new_user_coupon(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
    	return BaseDTOJTO.toJsonForCheck_new_user_coupon();
    }
    
    //检测店铺列表页modal 
    @RequestMapping("/check_store_list_modal")
    public Object check_store_list_modal(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
    	return BaseDTOJTO.toJsonForCheck_store_list_modal();
    }

    /**
     * 调用支付
     * @param f_user_id
     * @param order_no
     * @param mobile_type
     * @param pay_flag
     * @return
     */
    @RequestMapping("/ready_pay")
    public PayResult pay(String f_user_id,String order_no,String mobile_type, String pay_flag){
        return wordPadService.pay(f_user_id, order_no, mobile_type, pay_flag);
    }


    /**
     * 库存展示
     * @param f_user_id
     * @param store_id
     * @param mobile_type
     * @param date
     * @param admin_id
     * @param service_type
     * @return
     */

    @RequestMapping("/time_appointment")
    public PayResult time_appointment(Long f_user_id,Long store_id,String mobile_type, String date,Long admin_id,Integer service_type){
        return wordPadService.time_appointment(f_user_id,store_id, mobile_type, date, admin_id, service_type);
    }


    /**
     * 排班发型师列表
     * @param f_user_id
     * @param store_id
     * @param mobile_type
     * @param service_type
     * @return
     */

    @RequestMapping("/get_admin_list")
    public PayResult get_admin_list(Long f_user_id,Long store_id,String mobile_type,Integer service_type){
        return wordPadService.get_admin_list(f_user_id, store_id, mobile_type, service_type);
    }


    /**
     * 添加创建订单
     * @param orderAddParameterDto
     * @return
     */
    @GetMapping("/order_add")
    public OrderAdd orderAdd(OrderAddParameterDto orderAddParameterDto){
        log.info("insert order_add:{}", JSON.toJSONString(orderAddParameterDto));
        OrderAdd orderAdd = commentsService.orderAdd(orderAddParameterDto);
        return orderAdd;
    }



    /**
     * 下单详情 核对订单
     * @param payDetailParameterDto
     * @return
     */
    @GetMapping("/pay_detail")
    public PayDetail payDetail(PayDetailParameterDto payDetailParameterDto){
        PayDetail payDetail = commentsService.payDetail(payDetailParameterDto);
        return payDetail;
    }



    /**
     * 取消订单
     * @param f_user_id
     * @param order_no
     * @return
     */
    @GetMapping("/cancel_pay")
    public CancelPay cancelOrder(String f_user_id, String order_no){
        CancelPay cancelPay = orderRemoteService.cancelOrder(f_user_id, order_no);
        return cancelPay;
    }


    /**
     * 修改预约时间(支付后)pay_detail
     * @param appointmentParamDto
     * @return
     */
    @GetMapping("/change_appointment")
    public AppointmentSubmit changeAppointment(AppointmentParamDto appointmentParamDto){
        AppointmentSubmit appointmentSubmit = commentsService.changeAppointmentTime(appointmentParamDto);
        return appointmentSubmit;
    }



    /**
     * 修改预约时间(核对订单)
     * @param appointmentParamDto
     * @return
     */
    @GetMapping("/change_order")
    public AppointmentSubmit changeAppointments(AppointmentParamDto appointmentParamDto){
        AppointmentSubmit appointmentSubmit = commentsService.changeAppointment(appointmentParamDto);
        return appointmentSubmit;
    }

    /**
     * @description  目前没用 检查是否有新用户券 http://wiki.xingkeduo.com/pages/viewpage.action?pageId=1410018
     * @Author 情绪极其不稳定的Shadow
     * @Param [dto]
     * @return com.xingkeduo.dto.transter.appointment.AppointmentSubmit
     **/
    @GetMapping("/check_new_user_coupon")
    public AppointmentSubmit checkNewUserCoupon(CheckNewUserCouponDto dto){
        AppointmentSubmit appointmentSubmit = new AppointmentSubmit();
        appointmentSubmit.setReason(0);
        appointmentSubmit.setError(0);
        appointmentSubmit.setContent(false);
        return appointmentSubmit;
    }


    /**
     * 权益卡认证上传图片
     *
     * @param file
     * @return
     */
    @PostMapping("/certify")
    public CertifyResult certify(@RequestPart("file") MultipartFile file) {
        return commentsService.certify(file);
    }

    /**
     * 订单详情权益卡异常重新认证
     *
     * @param file
     * @return
     */
    @PostMapping("/abnormal_certify")
    public CertifyResult abnormal_certify(@RequestPart("file") MultipartFile file) {
        return commentsService.certify(file);
    }

}
